#include <stdio.h>
#include <unistd.h>

int main()
{
    int fd[2];
    int ret = pipe(fd);
    if(ret < 0)
    {
        perror("pipe");
        return 0;
    }

    printf("fd[0]:%d\n",fd[0]);
    printf("fd[1]:%d\n",fd[1]);

    //creat subprocess
    pid_t pid = fork();
    if(pid < 0)
    {
        perror("fork");
        return 0;
    }
    else if(pid == 0)
    {
        //child    
        printf("child:fd[0]:%d\n",fd[0]);
        printf("child:fd[1]:%d\n",fd[1]);
    }
    else 
    {
        printf("father:fd[0]:%d\n",fd[0]);
        printf("father:fd[1]:%d\n",fd[1]);
    }
    return 0;
}
